package com.common.ui;

import android.app.Activity;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Administrator on 2017/2/11.
 */

public class ActivityTaskManager {
    //保存activity链表
    private List<Activity> mActivityList = new LinkedList<Activity>();
    private ActivityTaskManager(){

    }

    /**
     * 单利模式
     */
    public static ActivityTaskManager getInstance(){
        return ExitApplicationHolder.sInstance;
    }

    /**
     * 添加activity
     * @param activity
     */
    public void addActivity(Activity activity){
        mActivityList.add(activity);
    }

    /**
     * 关闭所有的activity
     */
    public void exit(){
        for (Activity activity : mActivityList){
            activity.finish();
        }
    }

    public void remove(Activity activity){
        for (Activity ac : mActivityList){
            if(activity == ac){
                mActivityList.remove(ac);
                if(ac !=null){
                    ac.finish();
                }
            }
        }
    }
    private interface ExitApplicationHolder{
        ActivityTaskManager sInstance = new ActivityTaskManager();
    }
}
